/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
import { RootState } from "@/store";
import React, { ReactNode } from "react";
import { useSelector } from "react-redux";
import { Navigate } from "react-router-dom";
export interface IRequireAuthProps {
  children: ReactNode;
}

export default function RequireAuth(props: IRequireAuthProps) {
  const { isLogin } = useSelector((state: RootState) => state.user);
  console.log("守卫组件", isLogin);
  const guard = () => {
    return isLogin ? props.children : <Navigate to="/login" />;
  };
  return <>{guard()}</>;
}
